package sword_to_1;

import java.util.Arrays;

public class LeeCode_40_2 {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(dicesProbability(11)));
    }
    private static double[] dicesProbability(int n) {
        long[][] dp = new long[n + 1][n * 6 + 1];
        for (int i = 1; i <= 6; i++) {
            dp[1][i] = 1;
        }
        int count = 0;
        if (n == 1)
            count = 6;
        for (int i = 2; i < n + 1; i++) {
            boolean flag = i == n;
            for (int j = i; j <= 6 * i; j++) {
                int k = 1;
                long sum = 0;
                while (j - k > 0 && k <= 6){
                    sum += dp[i - 1][j - k];
                    k++;
                }
                dp[i][j] = sum;
                if (sum > 0 && flag){
                    count++;
                }
            }
        }
        double[] ans = new double[count];
        int index = 0;
        int tmp = 1;
        for (int i = 0; i < n; i++) {
            tmp *= 6;
        }
        for (int i = 0; i < n * 6 + 1; i++) {
            if (dp[n][i] != 0){
                ans[index++] = (double) dp[n][i] / tmp;
            }
        }
        return ans;
    }
}
